function initAttend() {
    //获取部门
    $('#deptChange').change(function(){
        var   dept_id = $(this).val();
        var   url = "getDeptUser/dept_id/"+dept_id;
        $.ajax({
            url: url,
            type: 'get',
            async: false,
            error:function(){
                alert(123);
            },
            success:function(data){
                console.log(data);
                $("#user").empty();
                var user_id = $('#user_id').val();
                var count = data.length;
                var i = 0;
                var b="";
                    b+='<option value="">选择人员</option>';
                    for(i=0;i<count;i++){
                        b+="<option value='"+data[i].user_id+"'"
                        if(user_id == data[i].user_id){
                            b+='selected';
                        }
                        b+=" >"+data[i].user_name+"</option>";
                    }
                $("#user").append(b);
            }
        });
    })
  
    $('.search').click(function () {
        var month = $('.timeList .active').text();
        var dept_id = $('.dept .active').attr('data-id');
        if(month){
            var pos = month.indexOf('月');
            var val = month.substring(0,pos);
            if(val<10){
                val = '0'+val;
            }
            var html = '<input type="hidden" name="month" value="'+val+'">';
            $('.timeList').after(html);
        }
        if(dept_id){
            var html = '<input type="hidden" name="dept_id" value="'+dept_id+'">';
            $('.dept').after(html);
        }
        $('form').submit();
    })

    $('.detail').click(function(){
        var url = $(this).attr('data-url');
        location.href = url;
    })
    
    $('.export').click(function(){
        var month = $('.timeList .active').text();
        var dept_id = $('.dept .active').attr('data-id');
        var year = $('#year').val();
        var url = 'exportPerform/';
        if(dept_id){
            url = url+'dept_id/'+dept_id;
        }
        if(year){
            url = url+'/year/'+year;
        }
        if(month){
            var pos = month.indexOf('月');
            var val = month.substring(0,pos);
            if(val<10){
                val = '0'+val;
            }
            url = url+'/month/'+val;
        }
        location.href = url;
    })
    
    
    //跳转
    $('.paging').on('click', function () {
        $('input[name=p]').remove();
        var data = $('form').serialize();
        var url = $(this).attr('data-url') + '?p=' + $('input[name=number]').val();
        location.href = url + data;
    })

    $('.layui-tab-title').on('click','li',function(){
        var type = $(this).attr('data-id');
        var dept_id = $("select[name='dept_id']").val();
        var time = $("input[name='time']").val();
        var url = 'absence/dept_id/'+dept_id+'/time/'+time+'/type/'+type+'/p/'+1;
        $.ajax({
            url: url,
            type: 'get',
            async: false,
            success: function (res) {
                console.log(res);
                if(res.type == 'leave'){
                    var html = '<table class="layui-table setTabBg out" lay-skin="line"><thead>';
                    html += '<tr><th>部门</th><th>姓名</th><th>请假类型</th><th width="20%">请假原因</th><th>请假天数</th><th>开始日期</th><th>结束日期</th><th>状态</th><th>操作</th></tr></thead><tbody>';
                    if (res['data'].length > 0) {
                        for (var i = 0; i < res['data'].length; i++) {
                            html += '<tr><td>' + res['data'][i].dept_name + '</td>';
                            html += '<td>' + res['data'][i].user_name + '</td>';
                            html += '<td>' + res['data'][i].leave_type2 + '</td>';
                            html += '<td>' + res['data'][i].leave_type + '</td>';
                            html += '<td>' + res['data'][i].leave_duration + '</td>';
                            html += '<td>' + res['data'][i].leave_date1 + '</td>';
                            html += '<td>' + res['data'][i].leave_date2 + '</td>';
                            if(res['data'][i].end_time){
                                html += '<td><font color="green">已结束</font></td>';
                            }else{
                                html += '<td><font color="red">待审批</font></td>';
                            }
                            html += '<td><span class="operationBtn delBtn" data-url="delAbsence/run_id/'+res['data'][i].run_id+'/type/leave" onmouseover="layer.tips(\'删除\', this,{tips:[1, \'#2D4271\'],time:500});"></span></td></tr>';
                        }
                    }
                    html += '</tbody></table>';
                    $('.absence').html(html);
                    $('.layui-block').text('共'+res['count']+'条数据');
//                    $('#page').html(res['pages']);
                }else if(res.type == 'evection'){
                    var html = '<table class="layui-table setTabBg evection" lay-skin="line"><thead>';
                    html += '<tr><th>部门</th><th>姓名</th><th>出差地点</th><th width="30%">出差事由</th><th>开始日期</th><th>结束日期</th><th>状态</th><th>操作</th></tr></thead><tbody>';
                    if (res['data'].length > 0) {
                        for (var i = 0; i < res['data'].length; i++) {
                            html += '<tr><td>' + res['data'][i].dept_name + '</td>';
                            html += '<td>' + res['data'][i].user_name + '</td>';
                            html += '<td>' + res['data'][i].evection_dest + '</td>';
                            html += '<td title='+res['data'][i].reason+'>' + res['data'][i].reason.substring(0,45) + '...</td>';
                            html += '<td>' + res['data'][i].evection_date1.substring(0,10) + '</td>';
                            html += '<td>' + res['data'][i].evection_date2.substring(0,10) + '</td>';
                            
                            if(res['data'][i].end_time){
                                html += '<td><font color="green">已结束</font></td>';
                            }else{
                                html += '<td><font color="red">待审批</font></td>';
                            }
                            html += '<td><span class="operationBtn delBtn" data-url="delAbsence/run_id/'+res['data'][i].run_id+'/type/evection" onmouseover="layer.tips(\'删除\', this,{tips:[1, \'#2D4271\'],time:500});"></span></td></tr>';
                        }
                    }
                    html += '</tbody></table>';
                    $('.absence').html(html);
                    $('.layui-block').text('共'+res['count']+'条数据');
//                    $('#page').html(res['pages']);
                }else if(res.type == 'out'){
                    var html = '<table class="layui-table setTabBg evection" lay-skin="line"><thead>';
                    html += '<tr><th>部门</th><th>姓名</th><th width="20%">外出原因</th><th>外出日期</th><th>外出时间</th><th>归来时间</th><th>状态</th><th>操作</th></tr></thead><tbody>';
                    if (res['data'].length > 0) {
                        for (var i = 0; i < res['data'].length; i++) {
                            html += '<tr><td>' + res['data'][i].dept_name + '</td>';
                            html += '<td>' + res['data'][i].user_name + '</td>';
                            html += '<td>' + res['data'][i].out_type + '</td>';
                            html += '<td>' + res['data'][i].out_date + '</td>';
                            html += '<td>' + res['data'][i].out_time1 + '</td>';
                            html += '<td>' + res['data'][i].out_time2 + '</td>';
                            if(res['data'][i].end_time){
                                html += '<td><font color="green">已结束</font></td>';
                            }else{
                                html += '<td><font color="red">待审批</font></td>';
                            }
                            html += '<td><span class="operationBtn delBtn" data-url="delAbsence/run_id/'+res['data'][i].run_id+'/type/out" onmouseover="layer.tips(\'删除\', this,{tips:[1, \'#2D4271\'],time:500});"></span></td></tr>';
                        }
                    }
                    html += '</tbody></table>';
                    $('.absence').html(html);
                    $('.layui-block').text('共'+res['count']+'条数据');
//                    $('#page').html(res['pages']);
                }
            }
        })
    })
}






